home *** CD-ROM | disk | FTP | other *** search
/ Komputer for Alle 2003 #3 / K-CD-3-2003.ISO / WinXP Service Pack 1 / xpsp1_sv_x86.exe / ipp_0001.as_ / ipp_0001.asp
Encoding:
Text File  |  2002-08-01  |  10.4 KB  |  315 lines

  1. ∩╗┐<%@ CODEPAGE=65001 %> 
  2. <%
  3. ' Replace the above line with your localized code page number
  4. '------------------------------------------------------------
  5. '
  6. ' Microsoft Internet Printing Project
  7. '
  8. ' Copyright (c) Microsoft Corporation. All rights reserved.
  9. '
  10. ' Entry page for queue view.
  11. '
  12. '------------------------------------------------------------
  13.     option explicit
  14. %>
  15. <!-- #include file = "ipp_util.inc" -->
  16.  
  17. <%
  18.  
  19. Randomize
  20. Response.Expires = 0
  21. Server.ScriptTimeOut = 6000 'Set time out to 10 minites
  22.  
  23. Const L_Opening_Text      = "├ûppnar"
  24. Const L_GetADSI_Message   = "H├ñmta ADSI-skrivare"
  25. Const L_AccessDenied_Text = "├àtkomst nekad"
  26.  
  27. Const ADSI_PRINTER_NAME     = 1
  28. Const ADSI_PRINTER_LOCATION = 2
  29. Const ADSI_PRINTER_COMMENT  = 3
  30. Const ADSI_PRINTER_MODEL    = 4
  31. Const ADSI_PRINTER_STATUS   = 5
  32. Const ADSI_PRINTER_JOBS     = 6
  33. Const ADSI_PRINTER_SHARE    = 7
  34. Const ADSI_PRINTER_ACCESS   = 8
  35. Const ADSI_PRINTER_ATTRIBUTES = 8
  36.  
  37. Const PRINTER_ACCESS_DENIED = 0
  38. Const PRINTER_OPENING       = 1
  39. Const PRINTER_OK            = 2
  40.  
  41.  
  42. Const iPrinterLength = 10
  43.  
  44. Function rgADSIGetPrinters(strComputer, iStart, iEnd)
  45.  
  46.     On Error Resume Next
  47.     Err.Clear
  48.  
  49.     Dim objPrinter, objPrinters, iPrinters, dwStatus, rgPrinters()
  50.     Dim objHelper, strServerName, i
  51.     Dim iTotal, iRevStart, iRevEnd
  52.  
  53.     Set objHelper = Server.CreateObject(PROGID_HELPER)
  54.  
  55.     If strComputer = "localhost" Or strComputer = "127.0.0.1" or Not objHelper.IsCluster Then
  56.         strComputer = objHelper.ComputerName
  57.     End If
  58.  
  59.     Set objPrinters = GetObject("WinNT://" & strComputer & ",computer")
  60.     If Err Then Exit Function
  61.     strServerName =  objPrinters.Name
  62.     objPrinters.filter = Array("PrintQueue")
  63.     If Err Then Exit Function
  64.  
  65.     ' iterate through all the (shared) printers
  66.     iTotal = 0
  67.     For Each objPrinter In objPrinters
  68.         iTotal = iTotal + 1
  69.     Next
  70.     iRevStart = iTotal - iEnd + 1
  71.     iRevEnd = iTotal - iStart + 1
  72.  
  73.     If iEnd <= iTotal Then bShowNext = TRUE
  74.  
  75.     iPrinters = 0
  76.     i = 1
  77.     For Each objPrinter In objPrinters
  78.  
  79.         If i > iRevEnd Then Exit For
  80.  
  81.         If i > iRevStart Then
  82.             iPrinters = iPrinters + 1
  83.  
  84.             ReDim Preserve rgPrinters(ADSI_PRINTER_ATTRIBUTES, iPrinters)
  85.             rgPrinters(ADSI_PRINTER_STATUS, iPrinters) = objPrinter.Status
  86.             If Err.Number = &H80070005 Then    'Access Denied
  87.                 Err.Clear
  88.                 rgPrinters(ADSI_PRINTER_NAME, iPrinters) = objPrinter.Name
  89.                 rgPrinters(ADSI_PRINTER_ACCESS, iPrinters) = PRINTER_ACCESS_DENIED
  90.                 rgPrinters(ADSI_PRINTER_LOCATION, iPrinters) = ""
  91.                 rgPrinters(ADSI_PRINTER_MODEL, iPrinters) = ""
  92.                 rgPrinters(ADSI_PRINTER_COMMENT, iPrinters) = "<a href=""ipp_0001.asp?v=1&startid=" &_
  93.                     CStr (iStart) & "&endid=" & CStr (iEnd) & """>" & L_AccessDenied_Text & "</a>"
  94.  
  95.                 rgPrinters(ADSI_PRINTER_JOBS, iPrinters) = 0
  96.             Else
  97.                 If Err.Number <> 0 Then
  98.                     Err.Clear
  99.                     rgPrinters(ADSI_PRINTER_NAME, iPrinters) = objPrinter.Name
  100.                     rgPrinters(ADSI_PRINTER_ACCESS, iPrinters) = PRINTER_OPENING
  101.                     rgPrinters(ADSI_PRINTER_LOCATION, iPrinters) = ""
  102.                     rgPrinters(ADSI_PRINTER_MODEL, iPrinters) = ""
  103.                     rgPrinters(ADSI_PRINTER_COMMENT, iPrinters) = L_Opening_Text
  104.                     rgPrinters(ADSI_PRINTER_JOBS, iPrinters) = 0
  105.                 Else
  106.                     dwStatus = objPrinter.Status
  107.                     If objPrinter.Attributes And &H400 Then dwStatus = dwStatus Or &H80
  108.  
  109.                     rgPrinters(ADSI_PRINTER_NAME, iPrinters) = GetFriendlyName (objPrinter.PrinterName, strServerName)
  110.                     rgPrinters(ADSI_PRINTER_STATUS, iPrinters) = dwStatus
  111.                     rgPrinters(ADSI_PRINTER_LOCATION, iPrinters) = strCleanString (objPrinter.Location)
  112.                     rgPrinters(ADSI_PRINTER_MODEL, iPrinters) = strCleanString (objPrinter.Model)
  113.                     rgPrinters(ADSI_PRINTER_COMMENT, iPrinters) = strCleanString (objPrinter.Description)
  114.                     rgPrinters(ADSI_PRINTER_JOBS, iPrinters) = objPrinter.JobCount
  115.                     If Err Then Exit Function
  116.  
  117.                     rgPrinters(ADSI_PRINTER_ACCESS, iPrinters) = PRINTER_OK
  118.                 End If
  119.             End If
  120.         End If
  121.  
  122.         i = i + 1
  123.     Next
  124.  
  125.     if iPrinters = 0 Then ReDim rgPrinters(ADSI_PRINTER_SHARE, 0)
  126.     rgADSIGetPrinters = rgPrinters
  127. End Function
  128.  
  129.     Dim strLocal, rgPrinters, strTitle
  130.     Dim iStart, iEnd, bShowNext
  131.  
  132.     'Verify User Name
  133.     If Request("v") = "1" And Session ("PASSWD_TYPED") = FALSE Then
  134.         Session ("PASSWD_TYPED") = TRUE
  135.         Err.Number = &H80070005
  136.         Call ErrorHandler(strADSI)
  137.     End If
  138.  
  139.     Session ("PASSWD_TYPED") = FALSE
  140.  
  141.     strLocal = request.ServerVariables("SERVER_NAME")
  142.     const L_AllPrinters_Text = "Alla skrivare p├Ñ %1"
  143.     strTitle = RepString1(L_AllPrinters_Text, strLocal)
  144.  
  145.     If Request("startid") = "" Or Request ("endid") = "" Then
  146.         iStart = 1
  147.         iEnd = iStart+ iPrinterLength
  148.     Else
  149.         iStart = Int (Request ("startid"))
  150.         iEnd = Int (Request ("endid"))
  151.         If (iEnd <= iStart) Then
  152.             iEnd = iStart + iPrinterLength
  153.         End If
  154.     End If
  155.  
  156.     bShowNext = FALSE
  157.  
  158.     rgPrinters = rgADSIGetPrinters(strLocal, iStart, iEnd)
  159.     If Err.Number <> 0 Then
  160.         Dim strADSI
  161.  
  162.         strADSI = L_GetADSI_Message
  163.  
  164.         Call ErrorHandler(strADSI)
  165.     End If
  166.  
  167.     SetCodePage
  168. %>
  169.  
  170. <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
  171. <html>
  172.  
  173. <head>
  174. <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
  175. <%=SetCodePage%>
  176. <meta http-equiv="refresh" content="120">
  177. <title><% =Write(strTitle) %></title> 
  178. </head>
  179.  
  180. <%
  181. Dim strPrinterName
  182. strPrinterName = "<H2>" & strTitle & "</H2>"
  183.  
  184.  
  185. Function GenTableHead ()
  186.     Dim L_TableTitle_Text(5)
  187.     Dim strTableTitle(5)       'The reason we have to do this is that when we manipulate the string ,
  188.                                'it is not localizable. This works around this problem
  189.     Dim i
  190.     Dim strHTML
  191.     Dim Width
  192.     'Width = Array (200, 80, 200, 37, 194, 194)
  193.     Const strSp = "  "
  194.  
  195.     L_TableTitle_Text(0) = "Namn"
  196.     L_TableTitle_Text(1) = "Status"
  197.     L_TableTitle_Text(2) = "Plats"
  198.     L_TableTitle_Text(3) = "Jobb"
  199.     L_TableTitle_Text(4) = "Modell"
  200.     L_TableTitle_Text(5) = "Kommentar"
  201.  
  202.     For i = 0 to 5
  203.         strTableTitle(i) = L_TableTitle_Text(i) & strSp
  204.     Next
  205.  
  206.     strHTML = "<tr>"
  207.  
  208.     For i = 0 to 5
  209.         strHTML = strHTML & "<td bgcolor=#000000 nowrap>" & MENU_FONT_TAG & "<b>" &_
  210.                   strTableTitle(i) & "</b>" & END_FONT & "</td>"
  211.     Next
  212.     strHTML = strHTML & "</tr>"
  213.  
  214.     GenTableHead = strHTML
  215. End Function
  216.  
  217. Function GenTableBody ()
  218.     Dim i
  219.     Dim strHTML
  220.  
  221.     Dim TdStart, TdEnd
  222.     TdStart = "<td nowrap>" & DEF_FONT_TAG
  223.     TdEnd = END_FONT & "</td>"
  224.  
  225.  
  226.     strHTML = ""
  227.     For i = ubound(rgPrinters, 2) To 1 Step -1
  228.     'For i = 1 To ubound(rgPrinters, 2)
  229.         strHTML = strHTML & "<tr>"
  230.  
  231.         Select Case rgPrinters(ADSI_PRINTER_ACCESS, i)
  232.         Case PRINTER_OPENING
  233.             strHTML = strHTML & TdStart & "<a href=""ipp_0001.asp" &_
  234.               """ target=""_top"">" & strCleanString(rgPrinters(ADSI_PRINTER_NAME, i)) & "</a>" & TdEnd
  235.         Case PRINTER_ACCESS_DENIED
  236.             strHTML = strHTML & TdStart & strCleanString(rgPrinters(ADSI_PRINTER_NAME, i)) & TdEnd
  237.         Case Else
  238.             strHTML = strHTML & TdStart & "<a href=""ipp_0004.asp?view=q&eprinter=" &_
  239.               OleCvt.EncodeUnicodeName(rgPrinters(ADSI_PRINTER_NAME, i)) &_
  240.               ATPAGE & CStr(Int(Rnd*10000)) &_
  241.               """ target=""_top"">" & strCleanString(rgPrinters(ADSI_PRINTER_NAME, i)) & "</a>" & TdEnd
  242.         End Select
  243.  
  244.         If rgPrinters(ADSI_PRINTER_ACCESS, i) = PRINTER_OK Then
  245.             strHTML = strHTML &_
  246.                       TdStart & strPrinterStatus (rgPrinters(ADSI_PRINTER_STATUS, i)) & TdEnd &_
  247.                       TdStart & rgPrinters(ADSI_PRINTER_LOCATION, i) & TdEnd &_
  248.                       TdStart & rgPrinters(ADSI_PRINTER_JOBS, i ) & TdEnd &_
  249.                       TdStart & rgPrinters(ADSI_PRINTER_MODEL, i) & TdEnd &_
  250.                       TdStart & rgPrinters(ADSI_PRINTER_COMMENT, i) & TdEnd
  251.         Else
  252.             strHTML = strHTML &_
  253.                       "<td>" & DEF_FONT_TAG & "<font color=""#7F7F7F"">" & rgPrinters(ADSI_PRINTER_COMMENT, i) & "</font>" & END_FONT & "</td>" &_
  254.                       "<td> </td>" &_
  255.                       "<td> </td>" &_
  256.                       "<td> </td>" &_
  257.                       "<td> </td>"
  258.         End If
  259.         strHTML = strHTML & "</tr>"
  260.     Next
  261.  
  262.     GenTableBody = strHTML
  263. End Function
  264. %>
  265.  
  266.  
  267.  
  268. <body bgcolor="#FFFFFF" text="#000000" link="#000000" vlink="#808080" alink="#000000"
  269. topmargin="0" leftmargin="0">
  270.  
  271. <table border="0" cellpadding="0" cellspacing="0" width="100%" height="175">
  272.   <tr>
  273.     <td width="100%"><table border="0" width="100%" cellspacing="0" cellpadding="1">
  274.       <tr>
  275.         <td width="12%"><img src="images/ipp_0002.gif" alt="printers.gif"></td>
  276.         <td width="88%"><%=Write(CLIENT_FONT & strPrinterName & END_FONT)%></td>
  277.       </tr>
  278.     </table>
  279.     </td>
  280.   </tr>
  281.   <tr>
  282.     <td height="11"></td>
  283.   </tr>
  284.   <tr>
  285.     <td  height="55"><table width=100% border="0" cellspacing="0" cellpadding="2">
  286.       <%=Write (GenTableHead)%>
  287.       <%=Write (GenTableBody)%>
  288.     </table>
  289.     </td>
  290.   </tr>
  291. </table>
  292.  
  293. <p>
  294.  
  295. <%
  296.     Dim strUrl
  297.     Const L_Prev_Text = "F├╢reg├Ñende %1 skrivare"
  298.     Const L_Next_Text = "N├ñsta %1 skrivare"
  299.             
  300.     strUrl = "<a target=_top href=ipp_0001.asp?startid=" & CStr(iStart - iPrinterLength) & "&endid=" & CStr(iEnd - iPrinterLength) & ">" & RepString1(L_Prev_Text, CStr (iPrinterLength)) & "</a>    "
  301.  
  302.     If iStart > 1 Then
  303.         Response.Write ( Write(DEF_FONT_TAG & strUrl & END_FONT))
  304.     End If
  305.  
  306.     strUrl = "<a target=_top href=ipp_0001.asp?startid=" & CStr(iStart + iPrinterLength) & "&endid=" & CStr(iEnd+iPrinterLength) & ">" & RepString1(L_Next_Text , CStr (iPrinterLength)) & "</a>"
  307.  
  308.     If bShowNext Then
  309.         Response.Write ( Write(DEF_FONT_TAG & strUrl & END_FONT))
  310.     End If
  311.  
  312. %>
  313. </body>
  314. </html>
  315.